//
//  BaseNacVC.m
//  OldHandPT
//
//  Created by ben on 2018/12/13.
//  Copyright © 2018 Shouny. All rights reserved.
//

#import "BaseNacVC.h"
#import "BaseVC.h"

@interface BaseNacVC ()

@end

@implementation BaseNacVC

-(void)SetupNavStyle
{
    if (kCurrentVersion < 7.0f)
    {
        [self.navigationBar setBackgroundImage:[[UIImage resizedImageWithName:@"Navigation_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)] forBarMetrics:UIBarMetricsDefault];
        if (kCurrentVersion > 6.f)
        {
            //去掉导航栏下边的投影
            self.navigationBar.shadowImage = [[BaseNacVC CreateImageWithColor:[UIColor clearColor]] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];
        }
    }else
    {
        [self.navigationBar setBackgroundImage:[[UIImage resizedImageWithName:@"Navigation_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 1, 5, 1)] forBarMetrics:UIBarMetricsDefault];
        self.navigationBar.tintColor = [UIColor whiteColor];
        //去掉导航栏下边的投影
        self.navigationBar.shadowImage = [[BaseNacVC CreateImageWithColor:[UIColor clearColor]] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];
    }
    self.navigationBar.barStyle = UIBarStyleBlack;
}

+ (UIImage *)CreateImageWithColor: (UIColor *) color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    [self SetupNavStyle];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //    [Utils dismissLoading];
    if (self.viewControllers.count) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_back" highIcon:@"icon_back" target:self action:@selector(back)];
        // 扩大点击范围
        UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:_IMG(@"icon_back") style:UIBarButtonItemStylePlain target:self action:@selector(back)];
        self.navigationItem.leftBarButtonItem = menuButton;
    }
    [super pushViewController:viewController animated:animated];
    
}

- (void)back{
    [self.view endEditing:YES];
    [self popViewControllerAnimated:YES];
}

@end
